using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WindBoost : MonoBehaviour
{
    public Transform player;
    float distance;

    float effectRadius;
    float windSpeed;
    Vector3 maxWindForce;
    Vector3 windForce;

    private void Start()
    {
        effectRadius = 10f;
        windSpeed = 1000f;
        maxWindForce = transform.forward.normalized * windSpeed;
        windForce = Vector3.zero;
    }

    void Update()
    {

        distance = Vector3.Distance(player.position, transform.position);
        if (distance <= effectRadius)
        {
            windForce = Vector3.Lerp(Vector3.zero, maxWindForce, (distance / effectRadius)*1.5F);
            var playerC = player.GetComponent<PlayerCharacter>();
            if (playerC.isBird)
            {
                //playerC.rigid.AddForce(Vector3.up * 1000);
                playerC.rigid.AddForce(maxWindForce * 2);
            }
            else
            {
                playerC.Jump(windForce.y * 0.01f);
            }
            
        }
    }

    private void OnDrawGizmos()
    {
        Gizmos.DrawSphere(transform.position, effectRadius);
    }
}
